VERSION = $0171 ;version number 1.7.1
nolist = 1 ;set to 0 to generate listing
 do nolist
 LST OFF
 else
 LST ON
 fin
 XC
 XC
 MX 3 ;8 BIT DATA, 8 BIT INDEXES
 TR ON
 DAT

debug = 0 ;set to 1 when using APW debugger

*
* This version is for the ProDev (DDT) production card. (IIGS ONLY)
*
* The default modes are invisible, 65816, emulate
*
* "PRODEV/DDT16"
* This Program is Public Domain
*
* Released by:
*
* PRODEV, INC.
* P.O. Box 162
* La Salle, MI  48145-0162
* www.prodev.biz
*
* BY: CHUCK KELLY
*

 ORG $2000 ;RUNS FROM $C800-$CFFF SPACE

 DSK DDT16OBJ
 PUT EQU1
 USE MACROS
 PUT SEG0
 PUT SEG1
 PUT SEG2
 PUT SEG3
 PUT SEG4
 PUT SEG5
 PUT SEG6
 PUT SEG7

 END

*** UPDATE NOTES ***

* V2.0.BB

* MAILED TO BETA TESTERS ON JUNE 22ND, 1987
* CORRECTS PROBELM OF ZAPPING BASL & BASH ZERO PAGE LOCATIONS WHEN IN
* SERIAL MODE.
* ADDS OPTIONAL ADDRESS TO "GO" COMMAND.
* AUTOMATICALLY INITIALIZES SSC WHEN I/O MODE FLAG IS SET TO SERIAL I/O
* BY USERS OWN INITIALIZATION ROUTINE.

* V2.0.BC

* MAILED TO DARACH FOSKETT ON JULY 21ST, 1987
* CORRECTS BUG WHEN "SED" OPCODE IS TRACED.
* ADDS DEFAULTS OF REAL AND 1 PASS TO "SB" COMMAND.
* DEFAULTS TO CURRENT BANK # RATHER THAN BANK #0.
* BANK NUMBER MUST BE FOLLOWED BY "/".
* "MM" EXIT COMMAND CHANGED FROM ":" TO ":<cr>".
* CORRECTS BUG PREVENTING DELETE FROM SERIAL TERMINAL.

* v2e1.0

* FIRST OFFICIAL RELEASE. MAILED TO ORIGIN SYSTEMS ON JULY 29TH, 1987
* CORRECTS PROBLEM WITH "ET" FROM V2.0.BC

* V2e1.1

* 11/25/87
* L or LI both produce a listing. The effective address window no longer
* displays the $C0 page. The effective address shows the correct bank #.
* Added titles to main display.

* v2e1.2x

* 12/26/87
* New method of realtime execution. Place a BRK at opcode of instruction
* to stop realtime execution at. Also do special check for ProDos MLI
* calls. This method also allows parameter passing to subroutines on
* the stack and the old method did not

* 1/1/88
* Disassemble the Prodos MLI calls

* 1/18/88
* Added STEP1 in SZEROFONE that traces 1 instruction, even our real BRK,
* (does not stop even if trace count reaches 0) then goes to the address
* in the ENABLTVC vector.
* [GO] Trace 1st instruction then go. Allows a "GO" when at a Breakpoint.

* 1/23/88
* Make more TRACE steps fit on the screen.
* Add "HEX" and "ADR" assembler directives.
* Show code generated by miniassembler.

* 2/2/88
* Add ERROR numbers.
*  01 = Invalid command
*  02 = Address expected (not used)
*  03 = Number expected (not used)
*  04 = Bad command parameter
*  05 = Illegal bank selected (not used)
*
*  10 = No room for additional Breakpoints
*
*  20 = Command will not work in ROM
*
* Corrected problem of locking up when an invalid Ram bank is selected.
*
 PAG
*-------------------------------
*    APPLE IIGS  VERSION       *
*-------------------------------

* 4/8/88
* Display all 65c816's registers.

* 4/20/88
* Corrected 16 bit register display. Display proper stack RAM.
* Save all 65c816's registers.
* Restore all 65c816's registers.

* 4/22/88
* Corrected CXIO routine
* Stopped trapping RESET
* Changed labels on main display
* Corrected STACK display to wrap around in 6502 mode

* 4/25/88
* Corrected CXROM space in EQU1 where PLB was inserted.

* 6/2/88
* Corrected LDAINDY so status flags are set properly.
* Corrected Stack display in 816 mode.

* 6/3/88
* Added .D, .B, .E commands.
* Made .A, .X, .Y, .S accept 16 bit inputs

* 7/18/88
*!!!!!!!!!!!!!!!!!!!!! PRAISE THE LORD !!!!!!!!!!!!!!!!!!!!!!!!!!!!
* Found bug in CXIO routine that caused system to bomb out when
* accessing banks other than 00. Changed STA $C006 to STA $E0/C006.

* 7/20/88
* Changed reset vector to point to Apple's own vector to eliminate
* hang ups on reset.

* 8/18/88  all files
* Optimized TRANSFR code for 65816.

* 9/9/88
* Completed stack housekeeping & display routines.

* 12/30/88
* Copied over the following changes from DDT8V1.4.1

* Corrected bug in DISFMES when the previous screen display was a
* full screen (i.e. ?). If WINDFLG is >=$80 it will now do an "ON"
* command to restore the windows.

* Added copyright notice to memory window.
* Changed "MO" command to update flag window

* Added options to the $Cn0F entry point. Enter with the accumulator
* containing the following:
* Acc = $02 = Button & BRKs are not enabled, writing to DDT is enabled,
*             accessing vectors ($FFE8-$FFFF) is OK.
* Acc = $03 = Button is only way into DDT, DDT is write protected,
*             accessing vectors is OK.
* Acc = xx  = Button & BRKs are enabled, writing to DDT is enabled,
*             !! WARNING !! accessing vectors turns on /INH flip-flop
*             and prevents access to Apple's $FFxx ROM space.

* 1/2/89
* Changed register modify command from ".REG" to "REG="

* 1/3/89
* Changed files to assemble into seperate binary disk files for loading
* into ROM simulator.

* Changed Mini-Assembler to always assemble 1 or 2 byte # numbers

* 1/4/89
* SEP #NN & REP #NN assemble & disassemble to 1 byte always

* 1/5/89
* LDA long & absolute effective address display removed

* 1/6/89
* Save & Restore condition of Super Hi-Res screen
* Added SD S (Super Hi-Res) on
* LDA dp corrected to reflect D register in effective address
* PER effective address corrected
* Bcc BRANCH OUT OF RANGE error corrected

* 1/17/89
* READAD in SEGONE. BB/XXXX will set MEMPBR, BB XXXX will not but LETTER3 will
*   be set to BB in both cases.

* 1/26/89
* Corrected "QU" & "*" commands.
* HB X/aaaa will set HALT_ALL which breaks program in all banks.
* Display "X/" in hardware break when HALTALL banks is selected.

* 2/2/89
* Corrected effective address of abs. long instructions.
* Calculating proper program bank when E=1.

* 2/7/89
* Killed bug that cleared upper byte of Y register during tracing.

* 3/7/89
* Corrected display problem caused when LDA/STA INDY was setting the decimal
* mode flag, put a REP #$C0 in SLOTRTS.
* Corrected display problem in new MO command.
* Added conditional assembly flag "debug" for use with APW debugger

* 3/21/89
* Added interrupt handling for fast interrupts

* 3/30/89
* Moved RTBRKFLG to TCOUNT area in EQU1 so it would be initialized to 0

* 5/03/89
* Corrected ET time by stoping counter in INTSTUFF.
* Display proper flags with P= command.

* 5/04/89
* Added "(x ~2.6)" message when ET command is done in fast mode
* Changed WRITE subroutine in all segments but 2.

* 5/06/89
* Fixed bug in INTSTUFF that did not correctly indentify NMIs & BRKs.

* 5/89 - 6/17/89
* Made DDT16 replace the GS vectors at $00/03FB for fast NMIs to use
* and at $E1/0010 for fast BRKs to use. If the flag VECTORS is set to
* non zero then the GS vectors will not be replaced. This will prevent
* the interrupts from working when the GS is in high speed mode.
* The DDT16 no longer forces the GS to run in slow speed. If this is
* required then change the byte at $CnFF to 0 or $FF.
*
* Added some polish to the operation of some display routines.
* Now at version DDT16V1.6B and shipping to beta testers.

* 6/20/89
* TOGSINT - Corrected stack to original value before pushing stuff back on.
* Note! Interrupts during tracing or executing code can not be tollerated.
* See the note in SZEROFONE in the execute setup routine if this feature is
* needed

*--------------- VERSION DDT16 1.9B
* 7/17/89
* Working on correcting problem with STZ $C036 not accessing the proper bank.
* Modified the C0n0 space routines to accomodate a new method.

*--------------- VERSION 0.21
* 8/12/89
* New method appears to be working. Corrected problems in (STA/LDA),X. The
* Decimal flag was getting set. This really messes up the display.

* 8/17/89
* Added EXEC_GO, code in INTSTUFF & COMDGO to prevent interrupts from occuring
* when the DDT is tracing code. A negative side effect of this code is; the
* state of the user's I flag can not be preserved if the user's instruction
* that we are tracing is attempting to change the I flag. The user may
* manually set the I flag then use the GO command.

* 8/19/89
* Having problem with random crashes when DDT is enabled and I do stuff in
* the control panel. I think the problem is with multiple interrupts so I have
* added SEI at each of my interrupt handlers to prevent reentrance. Also
* modified TOGSINT in SSIXFONE to properly restore the user's stack if in
* 8 bit mode

* 8/21/89
* Another attempt to cure the random crashes with the control panel.
* This time I think the problem was that I was not restoring the CXROM
* and enabling the user's slot ROM. These changes to TOGSINT use
* TOC0N0IO in EXECUTE to go to the user's interrupt handler with all
* ROM switches fully restored.

*--------------- VERSION 0.22
* 8/22/89
* Correcting problems with effective address calculations. [d] & [d],y were
* getting the effective address from the current program bank, but the direct
* page is always in bank 0. Added a new addressing mode $19. Mode $19 is used
* for absolute style addressing where no effective address is desired.
* Modified DISASM to prevent changing the currently displayed effective
* address if the instruction being disassembled does not have an effective
* address
* Mailed to Pelican Software

*--------------- VERSION 0.23
* 8/23/89
* Corrected crash that occured when pressing "esc" from MOde menu.
* Protection window gave false ACCESS HALTs on JMP & JSR. Changed CKACCES
* to not do check on mode AM_A_NE ($19).

* 8/30/89
* Corrected bug when AUX stack & zero page was on + Language card was set to
* RAM. This caused $FFxx to be in AUX bank and the /INH line would not work
* as described in the IIGS tech note #32. Changed the program and the DDT2
* PROM to disable RAM in $E1/9Fxx bank which is always in the first physical
* 64K of system memory. New PROM version is DDT2.3
***** DID NOT WORK SO WENT BACK TO $FFxx FOR NOW *****

* 9/02/89
* Changed copyright notice to Break window. Corrected bug with COMDRT and
* T range in protection window. Corrected bug in range checking for protection
* window that did not recognize lower bounds that were equal to the PC.

* 9/04/89
* Fixed bug in COMDJS & COMDTS.

* 9/13/89
* Put back slow vector replace routines.
* Mailed to Brian A. Rice Inc. a version similar to this.

*--------------- VERSION 0.24
* 9/14/89
* Made ER stop at RTL.
* Added MOde to enable tracing through user breaks. The default is to stop.
* Changed slot 1 MOde to support Pascal 1.1 protocol.
* Mailed to Brian A. Rice Inc. 9/15/89

*-------------- VERSION 0.25
* 11/11/89
* Finished correcting assembly bugs.

* 12/27/89
* Added TOSLOTC0 init to XFRIO routine in STWOFONE

* 03/17/90
* Corrected bug in INTSTUFF that was not vectoring the interrupts to the
* handlers in the slot space, by adding code to GSVECT routine in SEG6 that
* sets up the TEMP vector to point to the proper handler.

* 03/19/90
* Corrected display bug caused when GETCOMCR was being called from other
* segments but the "-1" was missing from the PEA address for JUMPSEG to use.

* 03/28/90
* Interrupt status was not being restored when the interrupt was not ours.
* Placed the REP #$FB, SEP #$xx into SEG7 I/O routine. Don't know why I
* didn't put them there to begin with.

*-------------- VERSION 0.27
* 07/07/90
* GO command was not restoring the user's I flag. GO command now pushes the
* user PC and Status on the stack and does an RTI. This does not allow 100%
* preservation of the stack but it is the only way I could think of to
* reenable interrupts with all of the user's conditions restored (E.G. CXROM,
* registers, etc.). The SEG7 I/O code is changed from a JML to an RTI for the
* GO command by the RESTSTUF routine.

*-------------- VERSION 0.28
* 07/12/90
* On the road to 0.29. This version does not work.

*-------------- VERSION 0.29
* 07/13/90
* Use GS BRK handler and replace vector at $E1/0070 with JSL $C0C0.
* This version works except for not being able to trace code in banks other
* than 00 when in emulation mode.

*-------------- VERSION 0.2A
* 07/14/90
* Replace $E1/0070 vector with JML $E0C45E and $00/03FB with BRK $EA.
* Trying to find a way to trace code in banks other than 00 when in emulation
* mode.

*-------------- VERSION 0.2B
* 07/16/90
* Uses PLP RTL method of going to user's code from SEG0 I/O code.
* Both version 0.2A and 0.2B have a problem because the E1/0070 vector is
* overwritten by the GS on boot. When the button is pressed to interrupt
* a program the BRK at $00/03FB will get sent to the GS BRK routine.

*-------------- VERSION 0.2C
* 07/16/90
* Started with version 0.29. Modified EXECUTE so processor is in proper mode
* before pushing the RTI stuff onto the user's stack so the stack works
* properly at page boundaries.
* Added check for PBR modifing opcodes when user is running in emulation mode.
* Forces PBR update so trace will follow user's code into other banks.

*-------------- VERSION 0.30
* 08/14/90
* Making trace 8 bit code in banks other than 0. Use PLP, RTL in SEG7 IO to
* force tracing in non zero banks. Interrupts must be disabled (which they
* must be anyway if you are running 8 bit code in non zero banks).
*
* 08/17/90
* GS must be set for slow speed when tracing. If in high speed it will be
* necessary to trace some instructions more than once. This is do to the
* asynchronous nature of the 1Mhz & 2.8Mhz system clocks and the hardware
* counter on the DDT which generates the NMIs for tracing. The GS clock
* switches to hi speed during execution of the RTI in CXIO code. The switching
* time varies by 1 slot clock cycle.
*
* 08/18/90
* When tracing, save the current PC in PCLOtr & PBRtr. Compare with PC after
* tracing. If they are the same then try tracing same instruction again. This
* should hide the problem of tracing in high speed mode caused by the
* asynchronous clocks.
*
*-------------- VERSION 0.31
* 08/29/90
* Changed STAs to CMPs in SEG 1 I/O for enabling user slots.
* Corrected bug in TS A so it accepts bank value. Use RTL at end of test
* subroutine.
*-------------- VERSION 0.32
* 09/04/90
* Moved part of INTSTUFF from SEG0 to SEG5 as INTANLYZ to make more room in
* SEG0. Moved associated routines from SEG6 to SEG5 & moved some commands
* from SEG5 to SEG1 to make room for stuff in SEG5.
* Changed the Pascal 1.1 interface to work with ports 1 & 2 for both input &
* output.
*-------------- VERSION 0.33
* 09/06/90
* Added support for JSL to COMDRT & "T" range of "PW". Note! The stack is
* treated as native. Failure will occur if user's code is 8 bit JSR & stack
* is at $101 or $100.
* 09/08/90
* Corrected bug of not disassembling MLI calls. This was caused when I stopped
* displaying effective addresses for JSRs.
* Added disassembly of Prodos16 calls.
*-------------- VERSION 0.34
* 09/10/90
* Replaced direct support of Super Serial Card with Input & Output routines
* for Pascal 1.1 interface. This should allow operation on any Serial or
* Parallel Printer interface, including the IIGS ports.
* 09/11/90
* PAGE2 bug. The GS serial firmware turns off the Page2 switch.
* Corrected serial I/O bugs: registers not displayed properly, MO command
* default "<2>" not displayed.
* Added Tool call to get address of BRK VARiables in GS RAM.
*-------------- VERSION 0.35
* 09/12/90
* Added command "**" - go to monitor with cloaking on.
*               "*"  - go to monitor with ^Y vector enabled
* 09/13/90
* SSIXFONE - LDX #NMICOUNT routine, when the DDT is in slot 7 an extra cycle
* must be allowed for because the BRA :TOP7 in SEG7 I/O code is at $C0FE, the
* prefetch of the next address references a new page at $C100, this causes
* the next instruction to require an extra cycle.
* 09/14/90
* Removed mode menu that prevented stopping at non DDT BRKs. Now stops at all
* BRKs. This was necessary because we now use the GS BRK handler.
*-------------------------------------------------
*    VERSION 1.0
* 09/20/90
* SZEROFONE - changed CHKCTRLX to CHKESC. "esc" key cancels tracing.
* 09/22/90
* Changed "INV" to "SAV" in status window, corrected "ET" times.
*-------------------------------------------------
*    VERSION 1.0.1
* 09/28/90
* SZEROFTWO - corrected bug of stack being decremented when tracing code when
* the bank register was certain values. Caused by BIT EMULATE in EXECUTE after
* the user's DBR had been restored.
* SSIXFONE - save the text color & restore, set to DDT standard so text is
* always visible.
* 09/29/90
* SONEFONE - Disable interrupts before jumping to monitor.
* SZEROFONE - when tracing 8 bit code, do not compate PBR to PBRtr to see
* if the code was really traced. Restore PBR with PBRtr and try again. Added
* TRACATEM count of trace attempts, after trying 256 times, assume the code
* is jumping to itself.
*-------------------------------------------------
*    VERSION 1.0.2
* Lost in the shuffle from 1.0.1 to 1.0.3. Just fighting with the trace problems
* that 1.0.3 appears to fix.
*-------------------------------------------------
*    VERSION 1.0.3
* 10/01/90
* NEW METHOD OF TRACING !!!!!
* Use Hard Break for tracing by placing user's stack location in hard break.
* When we do RTI the last byte is pulled from the user's "Stack" location.
* This causes an NMI at the proper time to allow the following instruction to
* be executed. IT actually works correctly for both 1Mhz & 2.8Mhz CPU speeds.
* This cures a lot of headaches I was having with the different cycle times &
* asnychronous clocks.
* With this new method the "Hard Break" is not active during "TRacing" or
* "EXecuting". No big deal, it was never available during "ET" before. This
* new trace method shares some routines & buffers with the "ET" command.
* 10/02/90
* Fixing bugs caused by all the changes I made.
* Fixed "ET" command.
* 10/06/90
* Fixing bugs in COMDRT & T range.
* Added Q= command. DANGER this command has immediate effect and will lock
* the system if the wrong bits are flipped.
* 10/08/90
* Changed "**" command.
* "** "  - Go to monitor, interrupts enabled, ^Y enabled.
* "** I" - Go to monitor, interrupts disabled, ^Y enabled.
* "** C" - Go to monitor, interrupts disabled, ^Y disabled, Cloaking device on
*-------------------------------------------------
*    VERSION 1.1
* 10/12/90
* SEG5 - Fixed bug in break handler so user's speed is preserved. Also found
* an apparent bug in the CXROM status in the break handler and fixed it.
* Signal an error if the user trys "RT" or "T" range JSL while in 8 bit mode.
* 10/15/90
* Tryed to disable button interrupt when tracing our real BRKs. I helped it
* a little, but it is still possible to cause an NMI when the DDT enables
* the VIA interrupts as part of the execute routine. So:
* !!!! Note !!!! Do not use the button interrupt while multi pass real BRKS
* are active.
*-------------------------------------------------
*    VERSION 1.2
* 10/26/90
* Changed SEG7 I/O routine to NOT use the top byte ($C080+n0). My new attempt
* at making the DDT16 without hardware mods. When the GS vectors to my I/O
* space after an NMI or BRK, OUT14 will go hi and set LS109 bottom. The
* address in I/O space at $80+n0 is used as part of the Pal trigger and
* therefore can not appear in SEG7 I/O code that is going to execute user code
*
* 11/5/90
* Seg1 I/O routine was writing to $C080+n0 which was reseting the LS273.
* Seg1 I/O routine was wrapping around to the next segment which was reseting
* the LS273, I changed the reset from $C0E0 to $C0E1.
*
*    VERSION 1.2.1
* 11-20-90
* At Eric's suggestion I made the Init entry point do an RTL if the user
* enters in native mode. Otherwise I do an RTS.
*
*    VERSION 1.2.2
* 12-10-90
* By user request the DDT text color is now White/DBlue. Fixed bug that
* prevented operation in slots 1-3. The DDT16 will now work in any slot.
*
* 12-22-90
* The DDT text color is now set to the user's text color.
* Fixed bug in routine that transfers IO stuff to SEG1 I/O space.
* ************ This version mailed to A2-Central on 12-28-90 ***********
*
*    VERSION 1.2.3
* Serial I/O now uses KEy value to pause.
* ------ mailed to 4 Beta users 1-2-91 ------

*    VERSION 1.2.4
* 1-2-91
* MO command now displays I/O choices by slot #.
* Removed extra blank line when tracing by 1s.

*    VERSION 1.2.5
* 4-20-91
* Added version number word at $CnFD for use by Init program.
* 5-1-91
* Fixed bug in $Cn04 entry point that did not save Acc which meant DDT
* was initialized into various states.

*    VERSION 1.2.6
* 6-28-91
* Working on Conditional breakpoints.

*    VERSLIN 1.3
* 7-15-91
* Conditional breaks work, added reset of LS109 bot to Cn00 entry to prevent
* lock ups on restart of the DDT.

*    VERSION 1.3.1
* 8-15-91
* Added STep command : Works like TRace command. TRace command now displays
* only the instruction being traced with no register info. This was a user
* request so that more instructions would fit on the screen.
* Added I flag : Setting I=1 disables interrupts by always forcing the I flag
* to 1 before executing each instruction.

*    VERSION 1.7
* Skipped over some version numbers to match the sequence of the DDT8.
* 8-05-93
* Cleaned up comments.
*
* Fixed problem with RT command. When system interrupts were active it would
* execute the JSL then get interrupted by the system and end up in ROM at
* $00/CO74 where it would try to place a BRK and fail so it would report
* error ^ERR20 "Can not write to ROM". This new method disables interrupts
* until the BRK can be set.
*
* Default to Trace mode after a BRK. This allows user's to use the
* skip command "down arrow", to skip over BRK instructions they have placed
* in their code.
*
* Made command routine in seg5 shorter.
